package com.mycompany.biblio.model;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Table(name="status")

@NamedQueries({
    @NamedQuery(name = Status.GET_ALL, query = "SELECT s FROM Status s ORDER BY s.datePublication DESC"),
    @NamedQuery(name = Status.GET_BY_NAME, query = "SELECT s FROM Status s WHERE s.IDStatut=?1")
})
public class Status implements Serializable 
{
    public static final String GET_ALL = "Status.GetAll";
    public static final String GET_BY_NAME = "Status.GetByName";
    
    public static final int PUBLIC=2;
    public static final int FRIEND_ONLY=1;
    public static final int PRIVATE=0;
    
    @Id
    @GeneratedValue
    @Column(name="IDStatut")
    private int IDStatut;
    
    @Lob
    @Column(name="contenu")
    private String contenu;
    
    @Column(name="datepub")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date datePublication;
    
    @Column (name="vision")
    private int vision;
    
    @ManyToOne
    private User proprietaire;
    
    @OneToMany(mappedBy = "status")
    List<Comment> listComments;
    
    @ManyToMany
    List<User> listLike;
    
    @Transient
    private StringWrapper newComment = new StringWrapper();

    public StringWrapper getNewComment() {
        return newComment;
    }

    public void setNewComment(StringWrapper newComment) {
        this.newComment = newComment;
    }

    public void setContenu(String contenu) {
        this.contenu = contenu;
    }
    
    public List<User> getListLike() {
        return listLike;
    }

    public void setListLike(List<User> listLike) {
        this.listLike = listLike;
    }

    public List<Comment> getListComments() {
        return listComments;
    }

    public void setListComments(List<Comment> listComments) {
        this.listComments = listComments;
    }

    public Status() {
    }
    
    public int getLikes()
    {
        return listLike.size();
    }
    
    public String getContenu() {
        return contenu;
    }

    public int getIDStatut() {
        return IDStatut;
    }

    public Date getDatePublication() {
        return datePublication;
    }

    public void setDatePublication(Date datePublication) {
        this.datePublication = datePublication;
    }

    public int getVision() {
        return vision;
    }

    public void setVision(int vision) {
        this.vision = vision;
    }

    public User getProprietaire() {
        return proprietaire;
    }

    public void setProprietaire(User proprietaire) {
        this.proprietaire = proprietaire;
    }

    @Override
    public String toString() {
        return "Statut{" + "IDStatut=" + IDStatut + ", contenu=" + contenu + ", datePublication=" + datePublication + ", vision=" + vision + ", proprietaire=" + proprietaire + '}';
    }
}
